package com.midea.ai.air.ui.more.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;

import com.bumptech.glide.Glide;
import com.midea.ai.air.R;
import com.midea.ai.air.common.BaseFragment;
import com.midea.ai.air.common.ConsVal;
import com.midea.ai.air.ui.home.ActivityDetails;
import com.midea.ai.air.ui.home.ActivityNotSlip;
import com.midea.ai.air.ui.more.MoreSettingAirExpert;
import com.midea.ai.air.ui.more.MoreSettingAirReport;
import com.midea.ai.air.ui.more.MoreSettingBrainpower;
import com.midea.ai.air.ui.more.MoreSettingCheckbrainpower;
import com.midea.ai.air.ui.more.MoreSettingElectricityReport;
import com.midea.ai.air.ui.more.MoreSettingLocationOnOff;
import com.midea.ai.air.ui.more.MoreSettingMyMessageActivity;
import com.midea.ai.air.ui.more.adapter.MainListAdapter;
import com.midea.ai.air.ui.more.data.MainListItem;
import com.midea.ai.air.utils.GlideRoundTransform;
import com.midea.ai.air.utils.JumpUtils;
import com.midea.ai.air.view.ListViewForScrollView;

import java.util.ArrayList;

/**
 * Created by ouyangdi on 2015/12/10.
 * "更多"页面，列表
 */
public class MoreListFragment extends BaseFragment {
    private ArrayList<MainListItem> listItem1, listItem2, listItem3, listItem4;
    private ListView mListView1, mListView2, mListView3, mListView4;
    private ImageView mHeadIcon;
    private AdapterView.OnItemClickListener mOnItemClickListener1, mOnItemClickListener2, mOnItemClickListener3, mOnItemClickListener4;
    private FrameLayout mLayoutPersonal;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_list_more, container, false);
        initData();
        initViews(view);
        return view;
    }

    /**
     * 初始化显示数据
     */
    private void initData() {
        listItem1 = new ArrayList<>();
        listItem1.add(new MainListItem(R.drawable.air_more_integral, "我的积分", true, true));
        listItem1.add(new MainListItem(R.drawable.air_more_family, "我的家庭", false, true));
        listItem1.add(new MainListItem(R.drawable.air_more_message, "我的消息", false, false));

        listItem2 = new ArrayList<>();
        listItem2.add(new MainListItem(R.drawable.air_more_air, "空气报告", false, true));
        listItem2.add(new MainListItem(R.drawable.air_more_electricity, "电量", false, true));
        listItem2.add(new MainListItem(R.drawable.air_more_check, "体检", false, true));
        listItem2.add(new MainListItem(R.drawable.air_more_ifttt, "智能联动", false, true));
        listItem2.add(new MainListItem(R.drawable.air_more_position_switch, "定位开关", false, true));
        listItem2.add(new MainListItem(R.drawable.air_more_air, "空气达人", false, false));

        listItem3 = new ArrayList<>();
        listItem3.add(new MainListItem(R.drawable.air_more_mall, "美的商城", false, true));
        listItem3.add(new MainListItem(R.drawable.air_more_service, "售后服务", false, true));
        listItem3.add(new MainListItem(R.drawable.air_more_forum, "美粉圈", false, false));

        listItem4 = new ArrayList<>();
        listItem4.add(new MainListItem(R.drawable.air_more_setting, "设置", false, false, ConsVal.ACTIVITY_TAG_SET));

        mOnItemClickListener1 = new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        //我的积分
                        break;
                    case 1:
                        //我的家庭
                        JumpUtils.toPage(getActivity(), getString(R.string.air_more_family_my_family), getString(R.string.nav_bar_more),
                                getString(R.string.air_more_family_add_member), ConsVal.ACTIVITY_TAG_MORE_FAMILY, ActivityDetails.class);
                        break;
                    case 2:
                        //我的消息
                        startActivity(new Intent(getActivity(), MoreSettingMyMessageActivity.class));
                        break;
                }
            }
        };

        mOnItemClickListener2 = new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        //空气报告

                        startActivity(new Intent(getActivity(), MoreSettingAirReport.class));
                        break;
                    case 1:
                        //电量

                        startActivity(new Intent(getActivity(), MoreSettingElectricityReport.class));
                        break;
                    case 2:
                        //智能体检

                        startActivity(new Intent(getActivity(), MoreSettingCheckbrainpower.class));
                        break;
                    case 3:
                        //智能联动
                        startActivity(new Intent(getActivity(), MoreSettingBrainpower.class));
                        break;
                    case 4:
                        //定位开关
                        startActivity(new Intent(getActivity(), MoreSettingLocationOnOff.class));
                        break;
                    case 5:
                        //空气达人
                        startActivity(new Intent(getActivity(), MoreSettingAirExpert.class));
                        break;
                    default:
                        break;
                }
            }
        };

        mOnItemClickListener3 = new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        //美的商城
                        JumpUtils.toPage(getActivity(), getString(R.string.air_more_mall), getString(R.string.nav_bar_more),
                                ConsVal.ACTIVITY_TAG_MALL_FAN, ActivityNotSlip.class);
                        break;
                    case 1:
                        break;
                    case 2:
                        //美粉圈
                        JumpUtils.toPage(getActivity(), getString(R.string.air_more_fan), getString(R.string.nav_bar_more),
                                ConsVal.ACTIVITY_TAG_MALL_FAN, ActivityNotSlip.class);
                        break;
                }
            }
        };

        mOnItemClickListener4 = new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                MainListItem item = (MainListItem) parent.getAdapter().getItem(position);
                JumpUtils.toPage(getActivity(), item.getStrName(), "更多", item.getToPageTag());
            }
        };
    }

    private void initViews(View view) {
        mHeadIcon = (ImageView) view.findViewById(R.id.imgView_icon);
        Glide.with(this).load(R.drawable.air_photo).transform(new GlideRoundTransform(getActivity(), getResources().getDimensionPixelOffset(R.dimen.height_45dp))).into(mHeadIcon);
        mLayoutPersonal = (FrameLayout) view.findViewById(R.id.more_personal);
        mLayoutPersonal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                JumpUtils.toPage(getActivity(), getResources().getString(R.string.air_more_person), getResources().getString(R.string.air_more_discover), ConsVal.ACTIVITY_TAG_MORE_PERSON);
            }
        });
        mListView1 = (ListViewForScrollView) view.findViewById(R.id.listView1);
        mListView2 = (ListViewForScrollView) view.findViewById(R.id.listView2);
        mListView3 = (ListViewForScrollView) view.findViewById(R.id.listView3);
        mListView4 = (ListViewForScrollView) view.findViewById(R.id.listView4);

        mListView1.setAdapter(new MainListAdapter(getActivity(), listItem1));
        mListView2.setAdapter(new MainListAdapter(getActivity(), listItem2));
        mListView3.setAdapter(new MainListAdapter(getActivity(), listItem3));
        mListView4.setAdapter(new MainListAdapter(getActivity(), listItem4));

        mListView1.setOnItemClickListener(mOnItemClickListener1);
        mListView2.setOnItemClickListener(mOnItemClickListener2);
        mListView3.setOnItemClickListener(mOnItemClickListener3);
        mListView4.setOnItemClickListener(mOnItemClickListener4);
    }
}

